{extend name="public:base" /}
{block name="content"}
<link rel="stylesheet" href="__CSS__/addcomon.css">
<div class="row" style="padding:15px;">
    <div class="col-xs-12">
        <form class="checkadmin" action="{:url('addrun')}" method="post">
            <div class="box">
            <div class="box-header" data-original-title="" style="height: 40px;">
                <h2><i class="glyphicon glyphicon-plus"></i>新增用户</h2>
            </div>
            <div class="add-box">
                <div class="box-left">
                    <div class="form-group">
                        <label>用户名称:</label>
                        <input type="text" name="username"  required class="form-control">
                    </div>
                    <div class="form-group">
                        <label>用户电话:</label>
                        <input type="text" name="phone"  required class="form-control">
                    </div>
                    <div class="form-group">
                        <label>密码:</label>
                        <input name="password" type="password" class="form-control" placeholder="不填默认为121314"/>
                    </div>
                    <div class="form-group">
                        <label>排序:</label>
                        <input name="sort" type="text" value="50"/>
                    </div>
                    <div class="form-group">
                        <label>是否启用:</label>
                        <input name="status" value="1" type="checkbox" checked />
                    </div>
                </div>
                <div class="box-pane-right">
                    <div class="form-group">
                        <label>部门:</label>
                        <select class="form-control" name="depar_id" id="depar">
                            <option value="0">请选择部门</option>
                            {volist name="depar" id="vo"}
                            <option value="{$vo.id}">{$vo.name}</option>
                            {/volist}
                        </select>
                    </div>
                    <div class="form-group">
                        <label>职位:</label>
                        <select class="form-control" name="position" id="position">
                            <option value="">请选择职位</option>
                            {volist name="position" id="vo"}
                            <option value="{$vo.id}">{$vo.name}</option>
                            {/volist}
                        </select>
                    </div>
                    <div class="form-group">
                        <label>权限:</label>
                        <select class="form-control" name="auth_id">
                            <option value="0">请选择角色</option>
                            {volist name="auth_groups" id="vo"}
                            <option value="{$vo.id}">{$vo.title}</option>
                            {/volist}
                        </select>
                    </div>
                    <div class="form-group">
                        <label>地区:</label>
                        <select class="form-control" name="dq_id" id="dq">
                            <option value="0">请选择地区</option>
                            {volist name="dq" id="vo"}
                                <option value="{$vo.id}">{$vo.name}</option>
                            {/volist}
                        </select>
                    </div>
                    <div class="form-group">
                        <label>门店:</label>
                        <select class="form-control" name="group_id" id="group">
                            <option value="0">请选择门店</option>
                            {volist name="group" id="vo"}
                            <option value="{$vo.id}">{$vo.title}</option>
                            {/volist}
                        </select>
                    </div>
                    <div class="form-group">
                        <label>邀约分组:</label>
                        <select class="form-control" name="ygroup_id" id="ygroup">
                            <option value="0">请选择邀约分组</option>
                            {volist name="ygroup" id="vo"}
                            <option value="{$vo.id}">{$vo.group_name}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="btn-box">
                    {:token()}
                    <input type="hidden" name="batch" value="true">
                    <button type="submit" class="btn btn-color-o" id="submit">确定</button>
                    <button type="reset" class="btn btn-color-g">重置</button>
                </div>
            </div>
        </div>
        </form>
    </div>
</div>
{/block}
{block name="js"}
<script>
    $('.checkadmin').ajaxForm({
        beforeSubmit: checkadminForms, // 此方法主要是提交前执行的方法，根据需要设置
        success: complete2, // 这是提交后的方法
        dataType: 'json'
    });
    $(function () {
        var dq = $('#dq');
        var group = $('#group');
        var depar = $('#depar');
        var ygroup = $('#ygroup');
        dq.parent().hide();
        group.parent().hide();
        ygroup.parent().hide();
        depar.change(function () {
            if($(this).val()!=3){
                $.ajax({
                    type: "POST",
                    url:  "{:url('getmendian')}",
                    data: "depar_id="+$(this).val(),
                    success: function(info){
                        if(info[0]==undefined){
                            dq.parent().hide();
                            dq.removeAttr('name')
                            group.parent().hide();
                            ygroup.parent().hide();
                            group.removeAttr('name')
                            ygroup.removeAttr('name')
                        }else{
                            dq.parent().show();
                            dq.attr('name','dq_id');
                            group.attr('name','group_id');
                            ygroup.parent().hide();
                            ygroup.removeAttr('name')
                        }
                    }
                });
            }else{
                $.ajax({
                    type: "POST",
                    url:  "{:url('ygroup/getfenzu')}",
                    data: "depar_id="+$(this).val(),
                    success: function(info){
                        if(info[0]==undefined){
                            dq.parent().hide();
                            dq.removeAttr('name')
                            group.parent().hide();
                            ygroup.parent().hide();
                            group.removeAttr('name');
                            ygroup.removeAttr('name');
                        }else{
                            ygroup.parent().show();
                            ygroup.attr('name','ygroup_id');
                            dq.parent().hide();
                            dq.removeAttr('name');
                            group.parent().hide();
                            group.removeAttr('name');
                        }
                    }
                });
            }
        });
        dq.change(function () {
            $.ajax({
                type: "POST",
                url:  "{:url('getgroup')}",
                data: "depar_id="+depar.val()+"&dq_id="+$(this).val(),
                success: function(info){
                    console.log(info);
                    group.parent().show();
                    group.empty();
                    $("<option value=''>请选择门店</optinon>").appendTo(group);
                    $.each(eval(info),function(i,n){
                        $("<option value="+n.id+">"+n.title+"</optinon>").appendTo(group);
                    });
                }
            });
        })
    });
    //admin表单检查
    function checkadminForms() {
        var admin_username = $.trim($('input[name="username"]').val()); //获取INPUT值
        var myReg = /^[\u4e00-\u9fa5]+$/;//验证中文
        if (admin_username.indexOf(" ") >= 0) {
            layer.alert('登录用户名包含了空格，请重新输入', {icon: 5}, function (index) {
                layer.close(index);
                $('input[name="username"]').focus();
            });
            return false;
        }
        if (!$('input[name="phone"]').val().match(/^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/)) {
            layer.alert('电话号码格式不正确', {icon: 5}, function (index) {
                layer.close(index);
                $('input[name="phone"]').focus();
            });
            return false;
        }
    }
    highlight_subnav("{:url('index')}");
</script>'
{/block}